package com.example.mybatis.demo1.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//@Aspect  //定义切面下?
@Component //控制反转
public class UserAspect {
    @Pointcut("execution(* com.example.mybatis.demo1.Controller.UserController.* (..))")
    public void pointcut(){ }

    //前置通知
    @Before("pointcut()")
    public void doBefore(){
        System.out.println("执⾏ Before⽅法 ");
    }

    @After("pointcut()")
    public void doAfter(){
        System.out.println("执⾏ After⽅法 ");
    }

    @AfterReturning("pointcut()")
    public void AfterReturning(){
        System.out.println("执⾏ AfterReturning⽅法 ");
    }


    @AfterThrowing("pointcut()")
    public void AfterThrowing(){
        System.out.println("执⾏ AfterThrowing⽅法 ");
    }

//    @Around("pointcut()")
//    public Object doAround(ProceedingJoinPoint joinPoint){
//        Object object = null;
//        System.out.println("执⾏ Around⽅法开始执行！");
//        try{
//            object=joinPoint.proceed();
//        }catch (Throwable throwable){
//            System.out.println("抛出异常！");
//            throwable.printStackTrace();
//        }
//        System.out.println("执⾏ Around⽅法执行结束！");
//        return object;
//    }

}
